<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<title>操作员授权</title>
		<script type="text/javascript" language="JavaScript" src="../script/common.js"></script>
		<script type="text/javascript" language="JavaScript" src="../script/tree.js"></script>
		<script type="text/javascript" language="JavaScript">
			var tree;
			var group;
			var orgLevel;
			var data;
			
			/*初始化页面*/
			function load() {
				group = parent.getGroup();
				orgLevel = parent.getOrgLevel();
				if (!group)
					return;
				writeTree();
			}
			/*查询后台子节点方法，查询结果为当前节点下一级的节点。此方法名不能修改*/
			function _startLoadXmlTree(sSrc, jsNode, newNode) {
				DWR.call("partyService.findModulesByGroup", orgLevel, group.id, sSrc, function(result) {
					var b = false;
					for(var i=0;(jsNode.obj.id == "root"||jsNode.checked)&&i<result.length;i++){
						var m = result[i]
						if (m.isSel) {b = true;break;}
					}
					for(var i=0;!b&&i<result.length;i++){
						result[i].isSel = jsNode.checked
					}
					_xmlFileLoaded(result, jsNode);
				})
			}
			
			
			var options = {
				click:"cbclick(this)"
			};
			
			function cbclick(obj) {
				var node = data[obj.id.split("_")[1]];
				node.checked = obj.checked;
				var o = node.obj;
				var pcb = $("checkbox_" + o.parent);
				while (pcb && obj.checked) {
					pcb.checked = obj.checked;
					var pnode = data[o.parent];
					pnode.checked = obj.checked;
					o = pnode.obj;
					if (o)
						pcb = $("checkbox_" + o.parent);
				}
				if (!obj.checked) {
					o = node.obj;
					pcb = $("checkbox_" + o.parent);
					while (pcb) {
						var bl = false;
						var pnode = data[o.parent];
						for (var i = 0; i < pnode.childNodes.length; i++) {
							var c = pnode.childNodes[i]
							if (c.checked)
								bl = true;
						}
						if (bl)
							break;
						pcb.checked = false;
						pnode.checked = false;
						o = pnode.obj;
						if (o)
							pcb = $("checkbox_" + o.parent);
					}
				}
				var ts = $(obj.parentNode.id + "-cont").getElementsByTagName("INPUT");
				for (var i = 0; i < ts.length; i++) {
					var cb = ts[i];
					cb.checked = obj.checked;
					node = data[cb.id.split("_")[1]];
					node.checked = obj.checked;
				}
			}
			
			
			function _createNode(obj) {
				var node ;
				var checked = obj.isSel;
				options.checked = checked;
				/*增加静态子节点方法，第一个参数为是否为叶子节点，根据实际需要可以使用不同的属性判断，此方法名不能修改*/
				node = createTreeNode(obj.pageUrl, obj.name, obj.id, "javascript:void(0)", "../images/tree/module.png", "../images/tree/module.png", options);
				node.obj = obj;
				node.checked = checked;
				data[obj.id] = node;
				return node;
			}
			/*生成树的根节点，并显示出根节点下一级的节点*/
			
			function writeTree() {
				data = {};
				webTreeHandler.init();
				tree = new LoadTree("系统功能模块", null, "javascript:void(0)", null, "../images/tree/root.png", "../images/tree/root.png", "");
				var obj = {id:"root"}
				tree.obj = obj;
				$("modstree").innerHTML = tree;
				tree.select();
			}
			
			
			function onSave() {
				var modules = [];
				tree.checked = true
				findSelected(tree, modules)
			
				var group = parent.tree.getSelected().obj.id;
				DWR.call("partyService.saveModuleAcl", modules, group, function() {
					showInformation("权限设定修改成功")
				},{disCtrl:findBtns(btnForm),loading:"modstree"})
			}
			function findSelected(parent, modules) {
				var length = modules.length;
				var children = parent.childNodes
				if (parent.checked) {
					if (!parent.open || parent.isLeaf) {
						modules.push(parent.obj.uniqueId + "," + (!parent.open && !parent.isLeaf))
					} else {
						for (var i = 0; i < children.length; i++) {
							var c = children[i]
							if (c.checked) {
								findSelected(c, modules)
							}
						}
						if (parent.obj.id != "root")
							modules.push(parent.obj.uniqueId + "," + false)
					}
				}
			}
			function onCancel() {
				parent.showTab('groupinfo', "tab_base")
			}
		</script>
	</head>
	
	<body onload="load()">
		<div id="modstree" class="treeDiv"></div>
		<form id="btnForm" name="btnForm">
			<p><button type="button" onclick="onSave()">保 存</button> <button type="button" onclick="onCancel()">取 消</button></p>
		</form>
	</body>
</html>